<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>登录</title>
	
	<!--图标库-->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    
	<link rel="stylesheet" href="css/style.css" type="text/css" />
	
</head>

<body>
    <div id="app">
        <div class="content" v-if="isShow">

            <div class="content_input">
                <div class="title">
                    <p>管理员登录</p>
                </div>
                <el-input v-model="user.UserName" clearable placeholder="用户名"></el-input>
                <el-input v-model="user.PassWord" clearable show-password placeholder="密码"></el-input>
                <div class="content_button">
                    <el-button type="primary" @click="SignIn()">登录</el-button>
                </div>
            </div>
            <div class="bottom">
                <a href="#">忘记密码？</a>
                <a href="javascript:void (0)" @click="reg()">注册</a>
            </div>
        </div>
        <div class="content" v-else>

            <div class="content_input">
                <div class="title">
                    <p>管理员注册</p>
                </div>
                <el-input v-model="user.UserName" clearable placeholder="用户名"></el-input>
                <el-input v-model="user.PassWord" clearable show-password placeholder="密码"></el-input>
                <el-input v-model="user.verify" clearable show-password placeholder="验证码"></el-input>
                <div class="content_button">
                    <el-button type="primary" @click="reg()">注册</el-button>
                </div>
            </div>
        </div>
    </div>


<script type="text/javascript" src="js/ribbon.js"></script>
<!-- 先引入 Vue -->
<script type="text/javascript"  src="js/vue.js"></script>
<!-- 引入组件库 -->
<script type="text/javascript"  src="js/index.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script type="text/javascript" >
    let v = new Vue({
        el: '#app',
        data() {
            return {
                user:{
                    UserName: '',
                    PassWord: '',
                    verify:""
                },
                isShow:true,
            }
        },
        methods: {
            SignIn() {
                axios.post("/admin/login",v.user).then(function (response){
                    if (response.data==1){
                        alert("登录成功");
                        location.href="/";
                    }else if (response.data==2){
                        alert("用户名不存在");
                    }else {
                        alert("密码错误");
                    }
                })
            },
            reg(){
                v.isShow=false;

                axios.post("/admin/reg",v.user).then(function (response){
                    if (response.data==1){
                        alert("注册成功");
                        location.href="/adminlogin.html";
                    }else {
                        alert("用户名已存在");
                    }
                })
            },
        }
    })
</script>

</body>
</html>